package options

import "io"

type KeyType int
type CapType int

const (
	KT_SM2_PRI KeyType = 1
	KT_SM2_PUB KeyType = 2
	KT_SM4     KeyType = 4

	CT_ENCRYPT CapType = 1
	CT_DECRYPT CapType = 2
	CT_SIGN    CapType = 4
	CT_VERIFY  CapType = 8
)

type KeyOptions struct {
	Mode    int    // 工作模式 对于 SM2 C1C2C3 = 1  C1C3C2 = 0
	KeyId   string // Key Id
	KeyType KeyType
	Cipher  string //
	Reader  io.Reader
	Writer  io.Writer
	// Ctx   context.Context
	ConfigMap map[string]string
}

func NewKeyOptions(ops ...KeyOption) *KeyOptions {
	ko := &KeyOptions{
		Mode:      0,
		KeyId:     "",
		KeyType:   0,
		ConfigMap: make(map[string]string),
	}
	for _, ofun := range ops {
		ofun(ko)
	}

	return ko
}

type KeyOption func(*KeyOptions)

func WithEntireOptions(value *KeyOptions) KeyOption {
	return func(kos *KeyOptions) {
		*kos = *value
	}
}

func WithKeyId(kid string) KeyOption {
	return func(kos *KeyOptions) {
		kos.KeyId = kid
	}
}

func WithMode(mode int) KeyOption {
	return func(kos *KeyOptions) {
		kos.Mode = mode
	}
}

func WithCipher(c string) KeyOption {
	return func(kos *KeyOptions) {
		kos.Cipher = c
	}
}

func WithKeyType(v KeyType) KeyOption {
	return func(kos *KeyOptions) {
		kos.KeyType = v
	}
}

func WithWriter(w io.Writer) KeyOption {
	return func(kos *KeyOptions) {
		kos.Writer = w
	}
}

func WithReader(r io.Reader) KeyOption {
	return func(kos *KeyOptions) {
		kos.Reader = r
	}
}
